#!/usr/bin/python
"""Unittest Examples
from http://www.swc.scipy.org/lec/unit.html
"""
import unittest

class TestAddition(unittest.TestCase):

    def test_zeroes(self):
        self.assertEqual(0 + 0, 0)
        self.assertEqual(5 + 0, 5)
        self.assertEqual(0 + 13.2, 13.2)

    def test_positive(self):
        self.assertEqual(123 + 456, 579)
        self.assertEqual(1.2e20 + 3.4e20, 4.6e20)

    def test_mixed(self):
        self.assertEqual(-19 + 20, 1)
        self.assertEqual(999 + -1, 998)
        self.assertEqual(-300.1 + -400.2, -700.3)

    
def running_sum(seq):
    result = seq[0:1]
    for i in range(1, len(seq)):
        result.append(result[i-1] + seq[i])
    return result

class SumTests(unittest.TestCase):

    def test_empty(self):
        self.assertEqual(running_sum([]), [])

    def test_single(self):
        self.assertEqual(running_sum([3]), [3])

    def test_double(self):
        self.assertEqual(running_sum([2, 9]), [2, 11])

    def test_long(self):
        self.assertEqual(running_sum([-3, 0, 3, -2, 5]), [-3, -3, 0, -2, 3])
    
    
if __name__ == '__main__':
    unittest.main()
        
